package snt.org;

import java.util.ArrayList;
import java.util.ListIterator;

import snt.org.neighborhood.INeighborhood;
import snt.org.operators.Crossover;
import snt.org.operators.Mutation;
import snt.org.replacement.IReplacement;
import snt.org.selection.ISelection;
import snt.org.statistics.Observer;
import snt.org.termination.Termination;


public abstract class Algorithm extends Thread{
	protected INeighborhood population;
	protected Evaluator evaluator;
	protected IReplacement replacement;
	protected ISelection selection;
	protected ISelection []selections;
	protected Crossover crossover;
	protected Mutation mutation;
	protected Termination termination;

	protected Observer observer;
	
	protected boolean _shouldEnd = false;
	
	
	public Algorithm() {
		super();
	}
	
	public Algorithm(String name){
		super(name);
	}

	public void setAlgorithm(INeighborhood population, Evaluator evaluator, IReplacement replacement, ISelection selection, Crossover crossover, Mutation mutation, Termination termination){
		this.population = population;
		this.evaluator = evaluator;
		this.replacement = replacement;
		this.selection = selection;
		this.crossover = crossover;
		this.mutation = mutation;
		this.termination = termination;		
	}
	
	public void setAlgorithmS(INeighborhood population, Evaluator evaluator, IReplacement replacement, ISelection []selections, Crossover crossover, Mutation mutation, Termination termination){
		this.population = population;
		this.evaluator = evaluator;
		this.replacement = replacement;
		this.selections = selections;
		this.crossover = crossover;
		this.mutation = mutation;
		this.termination = termination;		
	}

	
	public void attach(Observer obs){
		observer = obs;
	}
	
	public void dettach(Observer obs){
		observer = null;
	}
	
	public void notifyObserver(){
		observer.Update();
	}
	
	public void setNeighborhood (INeighborhood neighborhood){
		population = neighborhood;
	}
	
	public INeighborhood getNeighborhood (){
		return population;
	}
	
	public Evaluator getEvaluator(){
		return evaluator;
	}
	
	public void setTermination(Termination term){
		termination = term;
	}
	
	public void kill(){
		_shouldEnd = true;
	}
	
	public boolean shouldEnd(){
		return _shouldEnd;
	}
	
}
